/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package speakerphonesensor;

import Communication.Communicator;

/**
 *
 * @author gianmariospacagna
 */
public class SpeakerPhoneSensor {

    /**
     * @param args the command line arguments
     */
    CircularArray tempSamples;
    CircularArray lightSamples;
    int size;
    private Communicator myCommunicator;
    RealTimeMeasurement rtm;
    /*
     * 1=EarPiece
     * 2=SpeakerPhone
     */
    int speakersStatus;

    private SpeakerPhoneSensor(Communicator myCommunicator) {
    }

    private SpeakerPhoneSensor(Communicator myCommunicator, String size) {
        this.myCommunicator = myCommunicator;
        this.size = Integer.parseInt(size);
        this.tempSamples = new CircularArray(this.size);
        this.lightSamples = new CircularArray(this.size);



        rtm = new RealTimeMeasurement(this, myCommunicator, lightSamples, tempSamples);
        rtm.start();
        run();



    }

    private void run() {

        System.out.println("Application running");

        activateMeasurements();


    }

    void activateMeasurements() {
        rtm.activate();
    }

    void standbyeMeasurements() {
        rtm.standbye();
    }

    public static void main(String[] args) {
        // TODO code application logic here


        Communicator myCommunicator;
        if (args.length > 0) {
            myCommunicator = new Communicator(args[0]);
        } else {
            myCommunicator = new Communicator();
        }

        new SpeakerPhoneSensor(myCommunicator, args[1]);

        /*
        System.out.println("Measure of Temperature");
        Response measure=myCommunicator.measureTemp();
        
        System.out.println("Response received: "+measure.getType()+" "+measure.getValue());
        
        System.out.println("Measure of Light");
        measure=myCommunicator.measureLight();
        
        System.out.println("Response received: "+measure.getType()+" "+measure.getValue());
        
        System.out.println("Measure of Ax");
        measure=myCommunicator.measureAx();
        
        System.out.println("Response received: "+measure.getType()+" "+measure.getValue());
        
        System.out.println("Ok Message");
        measure=myCommunicator.ok();
        
        System.out.println("Response received: "+measure.getType()+" "+measure.getValue());
         */




    }

    void activeEarPiece() {
        if (speakersStatus == 2) {
            System.out.println("EarPiece activated");
            System.out.println("");
        }
        speakersStatus = 1;
    }

    void activateSpeakerPhone() {
        if (speakersStatus == 1) {
            System.out.println("SpeakerPhone activated");
            System.out.println("");
        }
        speakersStatus = 2;

    }
}
